package Controller.Customer;

import Dao.CustomerCompanyDao;
import Service.CustomerService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "selectAllCustomer", value = "/selectAllCustomer")
public class SelectAllCustomer extends HttpServlet {
    CustomerService customerService = new CustomerService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        CustomerCompanyDao customerCompanyDao = new CustomerCompanyDao();
        String nickname = request.getParameter("nickname");
        String name = request.getParameter("name");
        String company = request.getParameter("company");
        try {
            Map<String, Object> map = customerService.selectAll(nickname, name, company);
            List<String> clientList = customerCompanyDao.selectFirm(); // Assuming this method exists and is correctly implemented
            request.setAttribute("clientList", clientList);
            request.setAttribute("map",map);
            System.out.println("map: " + map);
            request.getRequestDispatcher("/ListCustomer.jsp").forward(request, response);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}